import { defineStore } from "pinia";
import { store } from "../index"

export const crumbsStore = defineStore({
    persist: {
        enabled: true, //开启数据持久化
        strategies: [
            {
                key: "details",
                storage: sessionStorage
            }
        ]
    },
    state: () => ({
        tabList: [
            {
                path: "/",
                name: "Main",
                label: "首页",
                icon: "house",
                url: "Home",
            },
        ],
    }),
 
    actions: {
        //更新面包屑数据
        selectMenu(val) {
            // 状态量
            const index = { status: true }
            if (val.name !== 'Main') {
                //判断是否有重复添加的数据
                this.tabList.forEach(element => {
                    if (element.name === val.name) {
                        index.status = false
                    }
                });
                if (index.status) {
                    this.tabList.push(val)
                }
                console.log(this.tabList)
            }
        },
    }
})

export function crumbsWithOut() {
    return crumbsStore(store);
}